import os
import shutil

if __name__ == '__main__':
    image_folder = 'E:/pycharm/Codes/img/image'  # 图片所在文件夹路径
    txt_folder = 'E:/pycharm/Codes/img/label'  # txt文件所在文件夹路径
    destination_folder = 'E:/pycharm/Codes/img/next_img'  # 目标文件夹路径

    # 遍历图片文件夹
    for root, dirs, files in os.walk(image_folder):
        for file in files:
            if file.endswith('.jpg') or file.endswith('.png'):  # 确保是图片文件
                image_path = os.path.join(root, file)
                txt_filename = file.replace('.jpg', '.txt').replace('.png', '.txt')  # 构造对应的txt文件名
                txt_path = os.path.join(txt_folder, txt_filename)

                if not os.path.exists(txt_path):  # 如果对应的txt文件不存在
                    shutil.move(image_path, destination_folder)  # 移动图片文件到目标文件夹
